<%@ page language="java" import="java.util.*" pageEncoding="utf-8" %>
<%@ page import="java.net.URLDecoder" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>--%>
<%
    String basePath = "http://192.168.1.120:8050/empMaven/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">
    <title>主页面</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

</head>
<body>
<a href="user/zz"><button>转账</button></a><p/>
    <%--${loginUser}--%>
    <%--${emps}--%>
    <center>
       <h1>欢迎第${num}位用户:${loginUser.name}${loginUser.role.roleName}登录
           <a href="user/out"><button>退出</button></a>
       </h1>
        <form action="emp/toMain" method="get">
            姓名:<input type="text" name="query.qename" value="<c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qename!=null}">${fenYe.query.qename}</c:if>">
            部门:
                <select name="query.qdeptNo">
                    <option value="">--请选择--</option>
                    <c:forEach items="${depts}" var="dept">
                        <option <c:if test="${fenYe!=null&&fenYe.query!=null&&dept.deptNo==fenYe.query.qdeptNo}">selected="selected"</c:if> value="${dept.deptNo}">${dept.deptNo}${dept.dname}</option>
                    </c:forEach>
                </select>
            入职时间:
                <input type="date" name="query.qstartHireDate" value="<c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qstartHireDate!=null}"><fmt:formatDate value="${fenYe.query.qstartHireDate}" pattern="yyyy-MM-dd"></fmt:formatDate></c:if>">--
                <input type="date" name="query.qendHireDate" value="<c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qendHireDate!=null}"><fmt:formatDate value="${fenYe.query.qendHireDate}" pattern="yyyy-MM-dd"></fmt:formatDate></c:if>">
            <input type="submit" value="搜索">
        </form>
        <%--该表单作用是全部删除--%>
        <form action="emp/delete" method="get" onsubmit="return confirm('是否全部删除?')">
            <table border="1">
                <tr>
                    <td>全选<input type="checkbox" id="all" ></td>
                    <td>员工编号</td>
                    <td>员工姓名</td>
                    <td>员工头像</td>
                    <td>岗位</td>
                    <td>领导编号</td>
                    <td>入职日期</td>
                    <td>薪资</td>
                    <td>奖金</td>
                    <td>部门名称</td>
                    <td>修改</td>
                    <td>删除</td>
                </tr>
                <c:forEach items="${emps}" var="e">
                    <tr>
                        <td><input type="checkbox" name="empNos" value="${e.empNo}"></td>
                        <td>${e.empNo}</td>
                        <td>${e.ename}</td>
                        <td><img src="${e.img}"/></td>
                            <%--
                                img/jhaskdhskahdksa.png
                                http://localhost:8090/jspEmp/img/jhaskdhskahdksa.png
                                D:/img/jspEmp/jhaskdhskahdksa.png
                            --%>
                        <td>${e.job}</td>
                        <td>${e.mgr}</td>
                        <td>
                            <c:if test="${e.hireDate!=null}"><fmt:formatDate value="${e.hireDate}" pattern="yyyy-MM-dd"></fmt:formatDate></c:if>
                        </td>
                        <td>${e.sal}</td>
                        <td>${e.comm}</td>
                        <td>${e.dept.deptNo}${e.dept.dname}</td>
                        <td><a href="emp/toUpdate?empNo=${e.empNo}">修改</a></td>
                        <td><a onclick="return confirm('是否确定删除?')" href="emp/deleteEmp?empNos=${e.empNo}">删除</a></td>
                    </tr>
                </c:forEach>
            </table>
            <p/>
            <a href="emp/toAdd"><input type="button" value="添加员工"></input></a>
            <input type="submit" value="全部删除">
        </form>

        <c:url var="url" value="emp/toMain">
            <c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qename!=null}">
                <c:param name="query.qename" value="${fenYe.query.qename}"></c:param>
            </c:if>
            <c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qdeptNo!=null}">
                <c:param name="query.qdeptNo" value="${fenYe.query.qdeptNo}"></c:param>
            </c:if>
            <c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qstartHireDate!=null}">
                <%--c:param标签的value里面不能直接使用fmt标签--%>
                <c:param name="query.qstartHireDate"><fmt:formatDate value="${fenYe.query.qstartHireDate}" pattern="yyyy-MM-dd"></fmt:formatDate></c:param>
            </c:if>
            <c:if test="${fenYe!=null&&fenYe.query!=null&&fenYe.query.qendHireDate!=null}">
                <%--c:param标签的value里面不能直接使用fmt标签--%>
                <c:param name="query.qendHireDate"><fmt:formatDate value="${fenYe.query.qendHireDate}" pattern="yyyy-MM-dd"></fmt:formatDate></c:param>
            </c:if>
            <c:param name="page"></c:param>
        </c:url>

        <a href="${url}1">首页</a>
        <c:choose>
            <c:when test="${fenYe.page<=1}">
                上一页
            </c:when>
            <c:otherwise>
                <a href="${url}${fenYe.page-1}">上一页</a>
            </c:otherwise>
        </c:choose>

        <c:forEach begin="1" end="${fenYe.pagesCount}" var="i">
            <a href="${url}${i}">${i}</a>
        </c:forEach>

        <c:choose>
            <c:when test="${fenYe.page>=fenYe.pagesCount}">
                下一页
            </c:when>
            <c:otherwise>
                <a href="${url}${fenYe.page+1}">下一页</a>
            </c:otherwise>
        </c:choose>
        <a href="${url}${fenYe.pagesCount}">尾页</a>
        &nbsp;&nbsp;&nbsp;&nbsp;当前第${fenYe.page}页&nbsp;&nbsp;&nbsp;&nbsp;共${fenYe.pagesCount}页
    </center>
</body>
<script type="text/javascript">
    //获取all全选框
    var all=document.getElementById("all");
    //给all全选框添加点击事件
    all.onclick=function(){
        //选择所有的多选框列表
        var empNos=document.getElementsByName("empNos");
        for(var i=0;i<empNos.length;i++){
            empNos[i].checked=all.checked;
        }
    }
</script>
</html>
